//身份令牌
const jwt = require("jsonwebtoken");
const secretKey = "wangs";
const time = "1h";
const getToken = (payload) => {
  const token = jwt.sign(payload, secretKey, { expiresIn: time });
  return token;
};

//验证信息
const deterToken = (token) => {
  let status = true;
  return jwt.verify(token, secretKey, (err, decoded) => {
    if (err) {
      status = false;
    }
    return status;
  });
};

const jxToken = (token) => {
  return jwt.verify(
    token,
    secretKey,
    { algorithms: ["HS256"] },
    (err, decoded) => {
      if (err) {
        console.log("error");
      } else {
        return decoded;
      }
    }
  );
};

module.exports = {
  getToken,
  deterToken,
  jxToken,
};
